package com.ruoyi.project.channel.clickFormUser.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.system.user.domain.User;
import org.apache.commons.collections4.map.HashedMap;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.clickFormUser.domain.ClickFormUser;
import com.ruoyi.project.channel.clickFormUser.service.IClickFormUserService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 刷单用户信息操作处理
 * 
 * @author CAIN
 * @date 2021-01-24
 */
@Controller
@RequestMapping("/channel/clickFormUser")
public class ClickFormUserController extends BaseController
{
    private String prefix = "channel/clickFormUser";
	
	@Autowired
	private IClickFormUserService clickFormUserService;
	
	@RequiresPermissions("channel:clickFormUser:view")
	@GetMapping()
	public String clickFormUser()
	{
	    return prefix + "/clickFormUser";
	}
	
	/**
	 * 查询刷单用户列表
	 */
	@RequiresPermissions("channel:clickFormUser:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ClickFormUser clickFormUser)
	{
		startPage();
        List<ClickFormUser> list = clickFormUserService.selectClickFormUserList(clickFormUser);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出刷单用户列表
	 */
	@RequiresPermissions("channel:clickFormUser:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClickFormUser clickFormUser)
    {
    	List<ClickFormUser> list = clickFormUserService.selectClickFormUserList(clickFormUser);
        ExcelUtil<ClickFormUser> util = new ExcelUtil<ClickFormUser>(ClickFormUser.class);
        return util.exportExcel(list, "clickFormUser");
    }
	
	/**
	 * 新增刷单用户
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
//	/**
//	 * 新增保存刷单用户
//	 */
//	@RequiresPermissions("channel:clickFormUser:add")
//	@Log(title = "刷单用户", businessType = BusinessType.INSERT)
//	@PostMapping("/add")
//	@ResponseBody
//	public AjaxResult addSave(ClickFormUser clickFormUser)
//	{
//		return toAjax(clickFormUserService.insertClickFormUser(clickFormUser));
//	}

	/**
	 * 修改刷单用户
	 */
	@GetMapping("/edit/{userId}")
	public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
	{
		ClickFormUser clickFormUser = clickFormUserService.selectClickFormUserById(userId);
		mmap.put("clickFormUser", clickFormUser);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存刷单用户
	 */
	@RequiresPermissions("channel:clickFormUser:edit")
	@Log(title = "刷单用户", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ClickFormUser clickFormUser)
	{		
		return toAjax(clickFormUserService.updateClickFormUser(clickFormUser));
	}
	
	/**
	 * 删除刷单用户
	 */
	@RequiresPermissions("channel:clickFormUser:remove")
	@Log(title = "刷单用户", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(clickFormUserService.deleteClickFormUserByIds(ids));
	}

	/**
	 * 确认绑定
	 */
	@Log(title = "我的信息", businessType = BusinessType.UPDATE)
	@GetMapping("/myInfo")
	@ResponseBody
	public AjaxResult getMyClickUserInfo() {
		User user = ShiroUtils.getSysUser();
		ClickFormUser clickFormUser = clickFormUserService.selectClickFormUserById(user.getUserId());
		if(user.getStatus().equals("1") || clickFormUser.getStatus().equals("1")){
			return AjaxResult.error("用户已经注销不可用！");
		}
		clickFormUser.setSalt("");
		clickFormUser.setApiKey("");
		clickFormUser.setPayPwd("");
		return AjaxResult.success("success", clickFormUser);
	}

}
